home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / xxi_appendice_dvd.swf / scripts / __Packages / CProspettiveDisplay.as < prev    next >
Text File  |  2007-11-08  |  9KB  |  324 lines

  1. class CProspettiveDisplay extends mx.core.UIObject
  2. {
  3.    var mSendLoadingDoneMessage = false;
  4.    var mHideDefaultLoadingBar = false;
  5.    var mPreloadFrame = 10;
  6.    function CProspettiveDisplay()
  7.    {
  8.       super();
  9.       this.doLater(this,"init");
  10.    }
  11.    function init()
  12.    {
  13.       this.mInitDone = false;
  14.       this.mDepth = this.getDepth();
  15.       this.mZoomed = false;
  16.       this.mZoomable = false;
  17.       this.mAutoScale = true;
  18.       if(_global.gVolume == undefined)
  19.       {
  20.          _global.gVolume = 50;
  21.       }
  22.       this.mX = this._x;
  23.       this.mY = this._y;
  24.       this.mContentX = 0;
  25.       this.mContentY = 0;
  26.       this.mContentScaleY = 100;
  27.       this.mContentScaleX = 100;
  28.       this.mWidth = this._width;
  29.       this.mHeight = this._height;
  30.       this._xscale = this._yscale = 100;
  31.       this.mFile = "";
  32.       this.mFrame = 0;
  33.       this.mLoading = false;
  34.       this.mc_Progress._visible = false;
  35.       this.createEmptyMovieClip("_content",this.getNextHighestDepth() + 1);
  36.       this.mSound = new Sound(this._content);
  37.       this.mSound.setVolume(_global.gVolume);
  38.       this.mPlaying = false;
  39.    }
  40.    function CreateBackground()
  41.    {
  42.       var _loc3_ = this.mWidth;
  43.       var _loc2_ = this.mHeight;
  44.       this.createEmptyMovieClip("_backgroundClip",this.getNextHighestDepth());
  45.       this._backgroundClip.beginFill(16777215);
  46.       this._backgroundClip.moveTo(0,0);
  47.       this._backgroundClip.lineTo(_loc3_,0);
  48.       this._backgroundClip.lineTo(_loc3_,_loc2_);
  49.       this._backgroundClip.lineTo(0,_loc2_);
  50.       this._backgroundClip.lineTo(0,0);
  51.       this._backgroundClip.endFill();
  52.    }
  53.    function CreateMask()
  54.    {
  55.       this.createEmptyMovieClip("_contentMask",this.getNextHighestDepth());
  56.       this._contentMask.beginFill(16711680);
  57.       this._contentMask.moveTo(0,0);
  58.       this._contentMask.lineTo(this.mWidth,0);
  59.       this._contentMask.lineTo(this.mWidth,this.mHeight);
  60.       this._contentMask.lineTo(0,this.mHeight);
  61.       this._contentMask.lineTo(0,0);
  62.       this._contentMask.endFill();
  63.       this.setMask(this._contentMask);
  64.    }
  65.    function SetMedia(inFile, inAutoScale, inZoomable, inShowMask)
  66.    {
  67.       this.mPlaying = false;
  68.       this.mAutoScale = inAutoScale;
  69.       this.mZoomable = inZoomable;
  70.       if(inShowMask)
  71.       {
  72.          this.setMask(this._contentMask);
  73.       }
  74.       else
  75.       {
  76.          this.setMask(null);
  77.       }
  78.       if(this.mZoomable)
  79.       {
  80.          this.onPress = this.onPressHandler;
  81.       }
  82.       else
  83.       {
  84.          delete this.onPress;
  85.       }
  86.       if(inFile != this.mFile)
  87.       {
  88.          if(this.mFile != "")
  89.          {
  90.             this._content.stop();
  91.             this._content.unloadMovie();
  92.          }
  93.          this.mFile = inFile;
  94.          this.mFrame = 0;
  95.          this.mLoading = true;
  96.          this.mInitDone = false;
  97.          this.mc_Progress.SetProgress(0);
  98.          if(!this.mHideDefaultLoadingBar)
  99.          {
  100.             this.mc_Progress._visible = true;
  101.          }
  102.          this.mTotalFrame = 0;
  103.          this.mSendLoadingDoneMessage = false;
  104.          this._content.loadMovie(this.mFile);
  105.          this.DoEvent("progess",0);
  106.       }
  107.       else
  108.       {
  109.          this.mc_Progress._visible = false;
  110.          if(!this.mLoading)
  111.          {
  112.             this.GoFrameAndStop(1,true);
  113.          }
  114.       }
  115.    }
  116.    function GoFrameAndStop(inMarker, inSendMessage)
  117.    {
  118.       if(this.mPlaying)
  119.       {
  120.          this.DoEvent("stateChange","pause");
  121.       }
  122.       this.mPlaying = false;
  123.       if(this.mFile != "")
  124.       {
  125.          this.mFrame = inMarker;
  126.          this._content.gotoAndStop(inMarker);
  127.          if(inSendMessage)
  128.          {
  129.             this.DoEvent("change",this.mFrame);
  130.          }
  131.       }
  132.    }
  133.    function GoFrameAndPlay(inMarker, inSendMessage)
  134.    {
  135.       if(!this.mPlaying)
  136.       {
  137.          this.DoEvent("stateChange","play");
  138.       }
  139.       this.mPlaying = true;
  140.       if(this.mFile != "")
  141.       {
  142.          this.mFrame = inMarker;
  143.          this._content.gotoAndPlay(inMarker);
  144.          if(inSendMessage)
  145.          {
  146.             this.DoEvent("change",this.mFrame);
  147.          }
  148.       }
  149.    }
  150.    function onEnterFrame(inValue)
  151.    {
  152.       if(this.mSendLoadingDoneMessage)
  153.       {
  154.          this.mSendLoadingDoneMessage = false;
  155.          this.DoEvent("loadingDone",100);
  156.       }
  157.       if(this.mLoading)
  158.       {
  159.          this.mSendLoadingDoneMessage = false;
  160.          if(this._content._totalframes > this.mPreloadFrame)
  161.          {
  162.             if(this.mTotalFrame == 0)
  163.             {
  164.                this.mTotalFrame = this._content._totalframes;
  165.                var _loc3_ = this._content._width;
  166.                var _loc2_ = this._content._height;
  167.                this.mContentX = 0;
  168.                this.mContentY = 0;
  169.                if(this._content.mc_ref)
  170.                {
  171.                   this.mContentX = - this._content.mc_ref._x;
  172.                   this.mContentY = - this._content.mc_ref._y;
  173.                   _loc3_ = this._content.mc_ref._width;
  174.                   _loc2_ = this._content.mc_ref._height;
  175.                }
  176.                this.mContentScaleX = 100;
  177.                this.mContentScaleY = 100;
  178.                if(this.mAutoScale && _loc3_ != 0 && _loc2_ != 0)
  179.                {
  180.                   this.mContentScaleX = 100 * this.mWidth / _loc3_;
  181.                   this.mContentScaleY = 100 * this.mHeight / _loc2_;
  182.                }
  183.                this._content._x = this.mContentX;
  184.                this._content._y = this.mContentY;
  185.                this._content._xscale = this.mContentScaleX;
  186.                this._content._yscale = this.mContentScaleY;
  187.                this._content._visible = true;
  188.                this._content.gotoAndStop(1);
  189.                this.DoEvent("loadinit",this.mTotalFrame);
  190.                this.mInitDone = true;
  191.             }
  192.             var _loc4_ = this._content._framesloaded;
  193.             var _loc5_ = this._content._totalframes;
  194.             var _loc6_ = Math.min(_loc4_ / _loc5_ * 100,100);
  195.             this.DoEvent("progess",_loc6_);
  196.             if(_loc4_ >= _loc5_)
  197.             {
  198.                this.DoEvent("progess",100);
  199.                this.mc_Progress._visible = false;
  200.                this.mLoading = false;
  201.                this.mSendLoadingDoneMessage = true;
  202.             }
  203.          }
  204.       }
  205.       if(this.mPlaying)
  206.       {
  207.          if(this.mFrame != this._content._currentframe)
  208.          {
  209.             this.mFrame = this._content._currentframe;
  210.             this.DoEvent("change",this.mFrame);
  211.          }
  212.          if(this.mFrame >= this.mTotalFrame && this.mTotalFrame > 10)
  213.          {
  214.             this._content.stop();
  215.             this.mPlaying = false;
  216.             this.DoEvent("complete",this.mFrame);
  217.          }
  218.       }
  219.    }
  220.    function DoEvent(inEvent, inArg)
  221.    {
  222.       this.dispatchEvent({type:"onDisplayEvent",target:this,event:inEvent,eventArg:inArg});
  223.    }
  224.    function onUnload()
  225.    {
  226.       this.setMask(null);
  227.       this._content.removeMovieClip();
  228.       this._contentMask.removeMovieClip();
  229.       delete this.mSound;
  230.       this.mSound = null;
  231.    }
  232.    function Shuffle(inPercent)
  233.    {
  234.       var _loc2_ = Math.ceil(inPercent * this.mTotalFrame / 100);
  235.       _loc2_ = Math.min(_loc2_,this.mTotalFrame);
  236.       _loc2_ = Math.max(_loc2_,0);
  237.       if(this.mPlaying)
  238.       {
  239.          this.GoFrameAndPlay(_loc2_,false);
  240.       }
  241.       else
  242.       {
  243.          this.GoFrameAndStop(_loc2_,false);
  244.       }
  245.       return _loc2_;
  246.    }
  247.    function Play()
  248.    {
  249.       this.mPlaying = true;
  250.       if(this._content._currentframe >= this._content._totalframes)
  251.       {
  252.          this._content.gotoAndPlay(1);
  253.       }
  254.       else
  255.       {
  256.          this._content.play();
  257.       }
  258.    }
  259.    function Stop()
  260.    {
  261.       this.GoFrameAndStop(1,true);
  262.    }
  263.    function Pause()
  264.    {
  265.       this.mPlaying = false;
  266.       this._content.stop();
  267.    }
  268.    function Rewind(inStep)
  269.    {
  270.       var _loc2_ = this._content._currentframe - inStep;
  271.       _loc2_ = Math.max(1,_loc2_);
  272.       if(this.mPlaying)
  273.       {
  274.          this.GoFrameAndPlay(_loc2_,true);
  275.       }
  276.       else
  277.       {
  278.          this.GoFrameAndStop(_loc2_,true);
  279.       }
  280.    }
  281.    function Forward(inStep)
  282.    {
  283.       var _loc2_ = this._content._currentframe + inStep;
  284.       _loc2_ = Math.min(this._content._totalframes,_loc2_);
  285.       _loc2_ = Math.min(_loc2_,this._content._framesloaded);
  286.       if(this.mPlaying)
  287.       {
  288.          this.GoFrameAndPlay(_loc2_,true);
  289.       }
  290.       else
  291.       {
  292.          this.GoFrameAndStop(_loc2_,true);
  293.       }
  294.    }
  295.    function SetVolume(inVolume)
  296.    {
  297.       this.mSound.setVolume(inVolume);
  298.       _global.gVolume = inVolume;
  299.    }
  300.    function GetVolume()
  301.    {
  302.       return this.mSound.getVolume();
  303.    }
  304.    function onPressHandler()
  305.    {
  306.       this._parent.ToggleZoom();
  307.    }
  308.    function ReleaseMemory()
  309.    {
  310.       if(this.mFile != "")
  311.       {
  312.          this._content.stop();
  313.          this._content.unloadMovie();
  314.       }
  315.       this.mFile = "";
  316.       this.mFrame = 0;
  317.       this.mLoading = false;
  318.       this.mPlaying = false;
  319.       this.mInitDone = false;
  320.       this.mc_Progress._visible = false;
  321.       this.mTotalFrame = 0;
  322.    }
  323. }
  324.